<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户设置页面</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.6.1/cropper.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        .set-body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            padding: 20px;
            color: #333;
        }

        .set-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .set-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 0;
            margin-bottom: 30px;
            border-bottom: 1px solid rgba(0,0,0,0.1);
        }

        .set-logo {
            font-size: 28px;
            font-weight: 700;
            color: #4361ee;
            display: flex;
            align-items: center;
        }

        .set-logo i {
            margin-right: 10px;
        }

        .set-settings-btn {
            background: #4361ee;
            color: white;
            border: none;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            font-size: 22px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
            box-shadow: 0 4px 12px rgba(67, 97, 238, 0.3);
        }

        .set-settings-btn:hover {
            background: #3a56d4;
            transform: rotate(30deg);
            box-shadow: 0 6px 15px rgba(67, 97, 238, 0.4);
        }

        .set-modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.6);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s ease;
        }

        .set-modal-overlay.active {
            opacity: 1;
            visibility: visible;
        }

        .set-settings-modal {
            background: white;
            border-radius: 12px;
            width: 90%;
            max-width: 800px;
            max-height: 90vh;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            transform: translateY(20px);
            transition: transform 0.4s ease;
        }

        .set-modal-overlay.active .set-settings-modal {
            transform: translateY(0);
        }

        .set-modal-header {
            background: linear-gradient(135deg, #4361ee 0%, #3a56d4 100%);
            color: white;
            padding: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .set-modal-header h2 {
            font-weight: 600;
            font-size: 22px;
        }

        .set-close-btn {
            background: none;
            border: none;
            color: white;
            font-size: 24px;
            cursor: pointer;
            transition: transform 0.3s ease;
        }

        .set-close-btn:hover {
            transform: rotate(90deg);
        }

        .set-modal-body {
            display: flex;
            min-height: 500px;
        }

        .set-settings-tabs {
            width: 200px;
            background: #f8f9fa;
            border-right: 1px solid #e9ecef;
        }

        .set-tab-btn {
            display: block;
            width: 100%;
            padding: 16px 20px;
            text-align: left;
            border: none;
            background: none;
            font-size: 16px;
            color: #495057;
            cursor: pointer;
            transition: all 0.2s ease;
            border-left: 4px solid transparent;
        }

        .set-tab-btn i {
            width: 24px;
            margin-right: 10px;
        }

        .set-tab-btn:hover, .set-tab-btn.active {
            background: #e9ecef;
            color: #4361ee;
            border-left: 4px solid #4361ee;
        }

        .set-settings-content {
            flex: 1;
            padding: 25px;
            overflow-y: auto;
        }

        .set-tab-content {
            display: none;
        }

        .set-tab-content.active {
            display: block;
            animation: set-fadeIn 0.4s ease;
        }

        @keyframes set-fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .set-section-title {
            font-size: 20px;
            margin-bottom: 25px;
            padding-bottom: 10px;
            border-bottom: 1px solid #e9ecef;
            color: #4361ee;
        }

        .set-form-group {
            margin-bottom: 20px;
        }

        .set-label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: #495057;
        }

        .set-input[type="text"],
        .set-input[type="password"],
        .set-input[type="email"],
        .set-textarea {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ced4da;
            border-radius: 6px;
            font-size: 16px;
            transition: border 0.3s ease;
        }

        .set-input:focus,
        .set-textarea:focus {
            outline: none;
            border-color: #4361ee;
            box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
        }

        .set-avatar-section {
            display: flex;
            flex-wrap: wrap;
            gap: 30px;
            margin-bottom: 30px;
        }

        .set-current-avatar {
            flex: 0 0 150px;
        }

        .set-current-avatar img {
            width: 150px;
            height: 150px;
            border-radius: 50%;
            object-fit: cover;
            border: 3px solid #4361ee;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
        }

        .set-avatar-upload {
            flex: 1;
            min-width: 300px;
        }

        .set-upload-btn {
            display: inline-block;
            padding: 10px 20px;
            background: #4361ee;
            color: white;
            border-radius: 6px;
            cursor: pointer;
            transition: background 0.3s ease;
            margin-bottom: 15px;
        }

        .set-upload-btn:hover {
            background: #3a56d4;
        }

        #set-avatar-input {
            display: none;
        }

        .set-crop-container {
            display: none;
            margin-top: 20px;
        }

        .set-crop-preview {
            width: 100%;
            height: 300px;
            background: #f8f9fa;
            border: 1px dashed #ced4da;
            border-radius: 6px;
            overflow: hidden;
            margin-bottom: 15px;
        }

        .set-crop-actions {
            display: flex;
            gap: 10px;
        }

        .set-btn {
            padding: 10px 20px;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .set-btn-primary {
            background: #4361ee;
            color: white;
        }

        .set-btn-primary:hover {
            background: #3a56d4;
        }

        .set-btn-secondary {
            background: #6c757d;
            color: white;
        }

        .set-btn-secondary:hover {
            background: #5a6268;
        }

        .set-submit-section {
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #e9ecef;
            text-align: right;
        }

        .set-submit-btn {
            padding: 12px 30px;
            font-size: 16px;
            font-weight: 500;
            background: #4361ee;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 10px rgba(67, 97, 238, 0.3);
        }

        .set-submit-btn:hover {
            background: #3a56d4;
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(67, 97, 238, 0.4);
        }

        .set-notification {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 15px 25px;
            background: #4caf50;
            color: white;
            border-radius: 6px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            transform: translateX(120%);
            transition: transform 0.4s ease;
            z-index: 1100;
        }

        .set-notification.show {
            transform: translateX(0);
        }

        @media (max-width: 768px) {
            .set-modal-body {
                flex-direction: column;
            }

            .set-settings-tabs {
                width: 100%;
                border-right: none;
                border-bottom: 1px solid #e9ecef;
                display: flex;
                overflow-x: auto;
            }

            .set-tab-btn {
                border-left: none;
                border-bottom: 4px solid transparent;
                text-align: center;
                padding: 15px 10px;
            }

            .set-tab-btn i {
                display: block;
                margin: 0 auto 5px;
            }

            .set-tab-btn:hover, .set-tab-btn.active {
                border-left: none;
                border-bottom: 4px solid #4361ee;
            }

            .set-avatar-section {
                flex-direction: column;
            }
        }
    </style>
</head>
<body class="set-body">
<div class="set-container">
    <div class="set-header">
        <div class="set-logo">
            <i class="fas fa-comments"></i>
            网页聊天系统
        </div>
        <button class="set-settings-btn" id="set-settingsBtn">
            <i class="fas fa-cog"></i>
        </button>
    </div>

    <h1>欢迎使用网页聊天系统</h1>
    <p>点击右上角的设置按钮修改您的个人信息、密码和邮箱。</p>
</div>

<!-- 设置模态框 -->
<div class="set-modal-overlay" id="set-settingsModal">
    <div class="set-settings-modal">
        <div class="set-modal-header">
            <h2><i class="fas fa-cog"></i> 用户设置</h2>
            <button class="set-close-btn" id="set-closeModal">
                <i class="fas fa-times"></i>
            </button>
        </div>

        <div class="set-modal-body">
            <div class="set-settings-tabs">
                <button class="set-tab-btn active" data-tab="set-profile">
                    <i class="fas fa-user"></i> 个人信息
                </button>
                <button class="set-tab-btn" data-tab="set-password">
                    <i class="fas fa-lock"></i> 修改密码
                </button>
                <button class="set-tab-btn" data-tab="set-email">
                    <i class="fas fa-envelope"></i> 修改邮箱
                </button>
                <button class="set-tab-btn" data-tab="set-privacy">
                    <i class="fas fa-shield-alt"></i> 隐私设置
                </button>
                <button class="set-tab-btn" data-tab="set-notifications">
                    <i class="fas fa-bell"></i> 通知设置
                </button>
            </div>

            <div class="set-settings-content">
                <!-- 个人信息设置 -->
                <div class="set-tab-content active" id="set-profile">
                    <h3 class="set-section-title">个人信息设置</h3>

                    <div class="set-form-group">
                        <label class="set-label" for="set-username">用户名</label>
                        <input type="text" class="set-input" id="set-username" value="张三">
                    </div>

                    <div class="set-form-group">
                        <label class="set-label" for="set-signature">个性签名</label>
                        <textarea class="set-textarea" id="set-signature" rows="3">热爱生活，热爱编程！</textarea>
                    </div>

                    <div class="set-avatar-section">
                        <div class="set-current-avatar">
                            <label class="set-label">当前头像</label>
                            <img src="https://randomuser.me/api/portraits/men/32.jpg" alt="用户头像">
                        </div>

                        <div class="set-avatar-upload">
                            <label class="set-label">上传新头像</label>
                            <div class="set-upload-btn" id="set-uploadTrigger">
                                <i class="fas fa-upload"></i> 选择图片
                            </div>
                            <input type="file" id="set-avatar-input" accept="image/*">

                            <div class="set-crop-container" id="set-cropContainer">
                                <div class="set-crop-preview" id="set-cropPreview"></div>
                                <div class="set-crop-actions">
                                    <button class="set-btn set-btn-primary" id="set-confirmCrop">
                                        <i class="fas fa-crop"></i> 确认裁剪
                                    </button>
                                    <button class="set-btn set-btn-secondary" id="set-cancelCrop">
                                        <i class="fas fa-times"></i> 取消
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="set-submit-section">
                        <button class="set-submit-btn" id="set-saveProfile">
                            <i class="fas fa-save"></i> 保存个人信息
                        </button>
                    </div>
                </div>

                <!-- 修改密码 -->
                <div class="set-tab-content" id="set-password">
                    <h3 class="set-section-title">修改密码</h3>

                    <div class="set-form-group">
                        <label class="set-label" for="set-currentPassword">当前密码</label>
                        <input type="password" class="set-input" id="set-currentPassword">
                    </div>

                    <div class="set-form-group">
                        <label class="set-label" for="set-newPassword">新密码</label>
                        <input type="password" class="set-input" id="set-newPassword">
                    </div>

                    <div class="set-form-group">
                        <label class="set-label" for="set-confirmPassword">确认新密码</label>
                        <input type="password" class="set-input" id="set-confirmPassword">
                    </div>

                    <div class="set-submit-section">
                        <button class="set-submit-btn" id="set-savePassword">
                            <i class="fas fa-save"></i> 更新密码
                        </button>
                    </div>
                </div>

                <!-- 修改邮箱 -->
                <div class="set-tab-content" id="set-email">
                    <h3 class="set-section-title">修改邮箱</h3>

                    <div class="set-form-group">
                        <label class="set-label" for="set-currentEmail">当前邮箱</label>
                        <input type="email" class="set-input" id="set-currentEmail" value="zhangsan@example.com" disabled>
                    </div>

                    <div class="set-form-group">
                        <label class="set-label" for="set-newEmail">新邮箱地址</label>
                        <input type="email" class="set-input" id="set-newEmail">
                    </div>

                    <div class="set-form-group">
                        <label class="set-label" for="set-emailPassword">当前密码</label>
                        <input type="password" class="set-input" id="set-emailPassword">
                    </div>

                    <div class="set-submit-section">
                        <button class="set-submit-btn" id="set-saveEmail">
                            <i class="fas fa-save"></i> 更新邮箱
                        </button>
                    </div>
                </div>

                <!-- 其他设置选项 -->
                <div class="set-tab-content" id="set-privacy">
                    <h3 class="set-section-title">隐私设置</h3>
                    <!-- 隐私设置内容 -->
                </div>

                <div class="set-tab-content" id="set-notifications">
                    <h3 class="set-section-title">通知设置</h3>
                    <!-- 通知设置内容 -->
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 通知 -->
<div class="set-notification" id="set-notification">
    <i class="fas fa-check-circle"></i> <span id="set-notificationText">设置已成功更新！</span>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.6.1/cropper.min.js"></script>
<script>
    $(document).ready(function() {
        // 设置模态框控制
        $('#set-settingsBtn').click(function() {
            $('#set-settingsModal').addClass('active');
        });

        $('#set-closeModal').click(function() {
            $('#set-settingsModal').removeClass('active');
        });

        // 选项卡切换
        $('.set-tab-btn').click(function() {
            $('.set-tab-btn').removeClass('active');
            $(this).addClass('active');

            const tabId = $(this).data('tab');
            $('.set-tab-content').removeClass('active');
            $('#' + tabId).addClass('active');
        });

        // 头像上传和裁剪
        let setCropper;

        $('#set-uploadTrigger').click(function() {
            $('#set-avatar-input').click();
        });

        $('#set-avatar-input').change(function(e) {
            if (e.target.files && e.target.files[0]) {
                const file = e.target.files[0];

                // 检查文件类型
                if (!file.type.match('image.*')) {
                    setShowNotification('请选择图片文件！', 'error');
                    return;
                }

                // 检查文件大小 (限制为5MB)
                if (file.size > 5 * 1024 * 1024) {
                    setShowNotification('图片大小不能超过5MB！', 'error');
                    return;
                }

                const reader = new FileReader();

                reader.onload = function(event) {
                    $('#set-cropContainer').show();

                    // 销毁现有的Cropper实例
                    if (setCropper) {
                        setCropper.destroy();
                    }

                    // 创建新的Cropper实例
                    const image = document.createElement('img');
                    image.id = 'set-cropImage';
                    image.src = event.target.result;
                    image.style.maxWidth = '100%';

                    $('#set-cropPreview').html(image);

                    setCropper = new Cropper(image, {
                        aspectRatio: 1,
                        viewMode: 1,
                        guides: true,
                        autoCropArea: 0.8,
                    });
                }

                reader.readAsDataURL(file);
            }
        });

        // 确认裁剪
        $('#set-confirmCrop').click(function() {
            if (setCropper) {
                // 获取裁剪后的图片数据
                const croppedCanvas = setCropper.getCroppedCanvas({
                    width: 300,
                    height: 300
                });

                // 转换为DataURL
                const croppedImage = croppedCanvas.toDataURL('image/jpeg');

                // 更新预览
                $('.set-current-avatar img').attr('src', croppedImage);

                // 隐藏裁剪区域
                $('#set-cropContainer').hide();

                setShowNotification('头像已更新，请保存设置！');
            }
        });

        // 取消裁剪
        $('#set-cancelCrop').click(function() {
            $('#set-cropContainer').hide();
            if (setCropper) {
                setCropper.destroy();
            }
        });

        // 保存个人信息
        $('#set-saveProfile').click(function() {
            const username = $('#set-username').val();
            const signature = $('#set-signature').val();
            const avatar = $('.set-current-avatar img').attr('src');

            // 这里应该是AJAX请求
            // $.post('/update-profile', {username, signature, avatar}, function(response) {
            //     if (response.success) {
            //         setShowNotification('个人信息已更新！');
            //     } else {
            //         setShowNotification('更新失败: ' + response.message, 'error');
            //     }
            // });

            // 模拟成功
            setShowNotification('个人信息已成功更新！');
        });

        // 保存密码
        $('#set-savePassword').click(function() {
            const currentPassword = $('#set-currentPassword').val();
            const newPassword = $('#set-newPassword').val();
            const confirmPassword = $('#set-confirmPassword').val();

            if (newPassword !== confirmPassword) {
                setShowNotification('两次输入的密码不一致！', 'error');
                return;
            }

            if (newPassword.length < 6) {
                setShowNotification('密码长度至少为6位！', 'error');
                return;
            }

            // 这里应该是AJAX请求
            // $.post('/update-password', {currentPassword, newPassword}, function(response) {
            //     if (response.success) {
            //         setShowNotification('密码已更新！');
            //         // 清空密码字段
            //         $('#set-currentPassword, #set-newPassword, #set-confirmPassword').val('');
            //     } else {
            //         setShowNotification('更新失败: ' + response.message, 'error');
            //     }
            // });

            // 模拟成功
            setShowNotification('密码已成功更新！');
            $('#set-currentPassword, #set-newPassword, #set-confirmPassword').val('');
        });

        // 保存邮箱
        $('#set-saveEmail').click(function() {
            const newEmail = $('#set-newEmail').val();
            const password = $('#set-emailPassword').val();

            if (!setValidateEmail(newEmail)) {
                setShowNotification('请输入有效的邮箱地址！', 'error');
                return;
            }

            // 这里应该是AJAX请求
            // $.post('/update-email', {newEmail, password}, function(response) {
            //     if (response.success) {
            //         setShowNotification('邮箱已更新！');
            //         $('#set-currentEmail').val(newEmail);
            //         $('#set-newEmail, #set-emailPassword').val('');
            //     } else {
            //         setShowNotification('更新失败: ' + response.message, 'error');
            //     }
            // });

            // 模拟成功
            setShowNotification('邮箱已成功更新！');
            $('#set-currentEmail').val(newEmail);
            $('#set-newEmail, #set-emailPassword').val('');
        });

        // 显示通知
        function setShowNotification(message, type = 'success') {
            $('#set-notificationText').text(message);
            $('#set-notification').removeClass().addClass('set-notification ' + type);
            $('#set-notification').addClass('show');

            setTimeout(function() {
                $('#set-notification').removeClass('show');
            }, 3000);
        }

        // 验证邮箱格式
        function setValidateEmail(email) {
            const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            return re.test(String(email).toLowerCase());
        }
    });
</script>
</body>
</html>